<template>
	<view class='bind_alipay'>
		<view class='form_box'>
			<view class='form_list'>
				<u-field v-model="real_name" label="姓名" placeholder="输入真实姓名"></u-field>
			</view>
			<view class='form_list'>
				<u-field v-model="alipay_sn" maxlength="11" label="帐号" placeholder="请填写手机号"></u-field>
			</view>
			<view class='form_list'>
				<u-field v-model="code" label="验证码" placeholder="请填写验证码">
					<u-button size="mini" slot="right" :custom-style="customStyle2" @click="getCode">{{codeText}}</u-button>
				</u-field>
				<u-verification-code ref="uCode" @change="codeChange"></u-verification-code>
			</view>

			<view class='hint'>注：为确保提无误，请填写支付宝认证真实姓名，并检查账号是否有误！</view>
		</view>

		<view class='form_btn'>
			<button class='btn' @click="subAlipay">确认绑定</button>
		</view>
		<pt-loading></pt-loading>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				code: '',
				alipay_sn: '',
				real_name: '',
				codeText: '获取验证码',
				customStyle2: {
					borderColor: '#141414', // 注意驼峰命名，并且值必须用引号包括，因为这是对象
					color: '#fff',
					background: '#141414'
				}
			};
		},
		methods: {
			codeChange(text) {
				this.codeText = text;
			},
			getCode() {
				if (this.$refs.uCode.canGetCode) {
					uni.showLoading({
						title: '正在获取验证码'
					})
					this.$u.apiWei.PhoneGetCode({
						login_code:'login',
						phone: this.alipay_sn
					}).then(res => {
						uni.hideLoading();
						// 通知验证码组件内部开始倒计时
						this.$refs.uCode.start();
					});
				} else {
					this.$u.toast('倒计时结束后再发送');
				}
			},
			subAlipay() {
				if (this.alipay_sn == '') {
					uni.showToast({
						title: '请输入支付宝账号',
						icon: "none",
						duration: 1000,
						mask: true
					})
					return false
				} else if (this.real_name == '') {
					uni.showToast({
						title: '请输入真实姓名',
						icon: "none",
						duration: 1000,
						mask: true
					})
					return false
				}
				let data = {
					alipay_sn: this.alipay_sn,
					real_name: this.real_name,
					code:this.code
				}
				this.$u.apiWei.BindingWallet(data).then(res => {
					uni.showToast({
						title: res.datas,
						icon: "none",
						duration: 1000,
						mask: true
					})
					setTimeout(() => {
						uni.navigateBack()
					}, 1000)
				})

			}
		}
	}
</script>

<style lang="scss">
	.bind_alipay {

		.form_box {
			width: 100%;
			background-color: #fff;
			margin-top: 10rpx;
			padding: 30rpx;
			font-size: 24rpx;
			color: #5E5E5E;
		}

		.form_list {
			display: flex;
			align-items: center;
			margin-bottom: 30rpx;
			/deep/ .u-field{
				flex: 1;
			}
		}

		.label {
			margin-right: 24rpx;
		}

		.ipt {
			flex: 1;
		}

		.ipt input {
			height: 66rpx;
			line-height: 66rpx;
			border: 1px solid #eee;
			padding: 0 20rpx;
			border-radius: 6rpx;
		}

		.hint {
			color: #FF0000;
			font-size: 18rpx;
		}

		.form_btn .btn {
			width: 554rpx;
			height: 90rpx;
			line-height: 90rpx;
			background-color: #141414;
			color: #fff;
			font-size: 24rpx;
			margin-top: 40rpx;
			border-radius: 12rpx;
		}

	}
</style>
